package com.lib.mapper;

import com.github.pagehelper.Page;
import com.lib.pojo.DTO.BookInformationDTO;
import com.lib.pojo.DTO.CategoryDTO;
import com.lib.pojo.DTO.PageDTO;
import com.lib.pojo.entity.BookInformation;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface LibraryMapper {

    //1:添加图书
    void addLibrary(BookInformation bookInformation);

    //2：根据id查询套餐
    @Select("select * from library.bookinformation where book_id = #{id}")
    BookInformation getById(Integer id);

    //3：根据分类id查询菜品
    List<BookInformation> getByCategoryId(Integer categoryId);

    //4：图书的起售、停售
    void statusStartOrStop(Integer status, Integer id);

    //5:批量删除    判断这个图书是否关联的有套餐
    List<Integer> UnifyId(List<Integer> ids);

    //5:批量删除    批量删除图书
    void delete(List<Integer> ids);

    //6:修改图书
    void putBook(BookInformationDTO bookInformationDTO);

    //7：图书分页查询
    Page<BookInformation> page(PageDTO pageDTO);

    //2：添加图书-把这本书属于的分类添加
    void putCategory(BookInformationDTO bookInformationDTO);

    //8：根据id删除图书
    void deleteById(Integer id);

    //8：根据关联的图书id分类
    @Delete("delete from library.book_category_infor where book_id = #{id}")
    void deleteGuanLianById(Integer id);
    @Delete("delete from library.book_re_infor where book_id = #{id}")
    void deleteRecommendById(Integer id);

    //获取分类id和分类名称
    @Select("select bci.category_id,category_name from library.bookcategory left join library.book_category_infor bci on bookcategory.category_id = bci.category_id where book_id = #{id}")
    List<CategoryDTO> getCategoryIdAndName(Integer id);

    //7：图书分页查询 获取所有图书
//    @Select("select * from library.bookinformation order by library.bookinformation.book_id")
    Page<BookInformation> pageAll(PageDTO pageDTO);

    //9：将指定图书添加到套餐
    @Insert("insert into library.book_re_infor (book_id,recommend_id) values(#{bookId},#{recommendId})")
    void addDishAndSetmeal(Integer bookId, Integer recommendId);


    //删除跟套餐关联的图书的id 关系
    @Delete("delete from library.book_re_infor where recommend_id = #{recommendId}")
    void deleteByRecommendId(Integer recommendId);
}
